const Cesium = window.Cesium;
import { formarColor, COLOR } from "../../Config";

class Radar {
    constructor(Entity, options, parentOptions) {
        if (!Entity) {
            throw new Error('至少传入一个 Entity 对象');
        };
        this.FontSize = window.REMFontSize || 1;
        this.Entity = Entity;
        this.radius = options.radius || 0;
        this.Entity = Entity;
        this.parentOptions = parentOptions;
        this.color = formarColor(this.parentOptions.color) || Cesium.Color.AQUAMARINE;
    }
    set show(type) {
        if (this.Entity.ellipse) {
            this.Entity.ellipse.show = !!type;
        } else if (this.Entity.ellipsoid) {
            this.Entity.ellipsoid.show = !!type;
        };
    }
    get show() {
        if (this.Entity.ellipsoid) {
            return this.Entity.ellipsoid.show
        } else if (this.Entity.ellipse) {
            return this.Entity.ellipse.show
        }
    }
    set Color(value) {
        this.color = formarColor(value);
        var _color = formarColor(value);
        if (this.Entity.ellipse) {
            this.Entity.ellipse.material = _color.withAlpha(0.5);
        } else {
            this.Entity.ellipsoid.material = _color.withAlpha(0.3);
            this.Entity.ellipsoid.outlineColor = _color.withAlpha(0.5);
        }
    }
    get Color() {
        return this.color
    }
    changeSenceType(type) {
        if (type == '3D') {
            this.Entity.ellipse = undefined;
            this.Entity.ellipsoid = this.render3DRadar();
        } else {
            this.Entity.ellipse = this.render2DRadar()
            this.Entity.ellipsoid = undefined;
        }
    }
    changeRadius(radius) {
        this.radius = radius;
        if (this.Entity.ellipse) {
            this.Entity.ellipse.semiMajorAxis = radius;
            this.Entity.ellipse.semiMinorAxis = radius;
        } else {
            this.Entity.ellipsoid.radii = new Cesium.Cartesian3(radius, radius, radius);
        }
    }
    render2DRadar() {
        return {
            material: this.color.withAlpha(0.5),
            semiMajorAxis: this.radius,
            semiMinorAxis: this.radius,
        }
    }
    render3DRadar() {
        return {
            radii: new Cesium.Cartesian3(this.radius, this.radius, this.radius),
            material: this.color.withAlpha(0.3),
            outline: true,
            outlineColor: this.color.withAlpha(0.5),
            outlineWidth: 1,
        }
    }

}



export { Radar }
